package com.lyf.boot.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.lyf.boot.enums.FileStoragePlatform;
import lombok.Data;
import org.dromara.x.file.storage.core.FileStorageProperties;
import org.dromara.x.file.storage.core.FileStorageServiceBuilder;
import org.dromara.x.file.storage.core.platform.FileStorage;

/**
 * @author Luyufan
 * @date 2023/8/15 11:26
 */
@Data
public class OssConfigProperties {

    /**
     * 平台类型
     */
    private String platformType;

    /**
     * 平台
     */
    private String platform;

    /**
     * 是否启用：0.禁用 1.启用
     */
    private Integer status;

    /**
     * 存储服务器access-key
     */
    private String accessKey;

    /**
     * 存储服务器secret-key
     */
    private String secretKey;

    /**
     * 服务器域名
     */
    private String endPoint;

    /**
     * 存储桶名称
     */
    private String bucketName;

    /**
     * 地区
     */
    private String region;

    /**
     * 访问域名
     */
    private String domain;

    /**
     * 基础路径
     */
    private String basePath;

    public FileStorage build(){
        if(StrUtil.equals(this.platformType, FileStoragePlatform.COS.getPlatform())){
            FileStorageProperties.TencentCosConfig tencentCosConfig = new FileStorageProperties.TencentCosConfig();
            BeanUtil.copyProperties(this, tencentCosConfig);
            tencentCosConfig.setSecretId(this.accessKey);
            return FileStorageServiceBuilder.buildTencentCosFileStorage(CollUtil.toList(tencentCosConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.OSS.getPlatform())){
            FileStorageProperties.AliyunOssConfig aliyunOssConfig = new FileStorageProperties.AliyunOssConfig();
            BeanUtil.copyProperties(this, aliyunOssConfig);
            return FileStorageServiceBuilder.buildAliyunOssFileStorage(CollUtil.toList(aliyunOssConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.OBS.getPlatform())){
            FileStorageProperties.HuaweiObsConfig huaweiObsConfig = new FileStorageProperties.HuaweiObsConfig();
            BeanUtil.copyProperties(this, huaweiObsConfig);
            return FileStorageServiceBuilder.buildHuaweiObsFileStorage(CollUtil.toList(huaweiObsConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.MINIO.getPlatform())){
            FileStorageProperties.MinioConfig minioConfig = new FileStorageProperties.MinioConfig();
            BeanUtil.copyProperties(this, minioConfig);
            return FileStorageServiceBuilder.buildMinioFileStorage(CollUtil.toList(minioConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.KODO.getPlatform())){
            FileStorageProperties.QiniuKodoConfig qiniuKodoConfig = new FileStorageProperties.QiniuKodoConfig();
            BeanUtil.copyProperties(this, qiniuKodoConfig);
            return FileStorageServiceBuilder.buildQiniuKodoFileStorage(CollUtil.toList(qiniuKodoConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.BOS.getPlatform())){
            FileStorageProperties.BaiduBosConfig baiduBosConfig = new FileStorageProperties.BaiduBosConfig();
            BeanUtil.copyProperties(this, baiduBosConfig);
            return FileStorageServiceBuilder.buildBaiduBosFileStorage(CollUtil.toList(baiduBosConfig), null).get(0);
        }else if(StrUtil.equals(this.platformType, FileStoragePlatform.USS.getPlatform())){
            FileStorageProperties.UpyunUssConfig upyunUssConfig = new FileStorageProperties.UpyunUssConfig();
            BeanUtil.copyProperties(this, upyunUssConfig);
            upyunUssConfig.setUsername(this.accessKey);
            upyunUssConfig.setPassword(this.secretKey);
            return FileStorageServiceBuilder.buildUpyunUssFileStorage(CollUtil.toList(upyunUssConfig), null).get(0);
        }
//        else if(StrUtil.equals(this.platformType, FileStoragePlatform.LOCAL_PLUS.getPlatform())){
//            FileStorageProperties.LocalPlusConfig localPlusConfig = new FileStorageProperties.LocalPlusConfig();
//            BeanUtil.copyProperties(this, localPlusConfig);
//            return FileStorageServiceBuilder.buildLocalPlusFileStorage(CollUtil.toList(localPlusConfig)).get(0);
//        }
        return null;
    }

}
